#include"process.h"
#include<time.h>
#include<stdlib.h>  //生成随机数以及随机数种子
typedef void (*call_t)(const char*,double,double); //函数指针类型，去年五月份或者六月份的时候学的，有一点忘记了


double speed[] = {1.0, 0.5, 0.3, 0.02, 0.1, 0.01};

double total = 1024.0;
void uploadload(double total,call_t ac)
{
  srand(time(NULL));
  double current = 0.0;
  while(current<=total)
  {
     ac("上传中", total, current); // 进行回调
     if(current>=total) break;
     // 下载代码
     int random = rand()%6;
     usleep(5000);
     current += speed[random];
     if(current>=total) current = total;
  }
}

void download(double total,call_t ac)
{
  srand(time(NULL));
  double current = 0.0;
  while(current<=total)
  {
     ac("下载中", total, current); // 进行回调
     if(current>=total) break;
     // 下载代码
     int random = rand()%6;
     usleep(5000);
     current += speed[random];
     if(current>=total) current = total;
  }
}


int main()
{


//   process_v1();
 download(1024.0,FlushProcess);
 uploadload(2026.0,FlushProcess);
  return 0;
}
